{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "import os\n",
    "\n",
    "os.chdir(\"../\")\n",
    "\n",
    "import hydra\n",
    "import matplotlib.pyplot as plt"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "hydra.core.global_hydra.GlobalHydra.instance().clear()\n",
    "hydra.initialize(version_base=\"1.3\", config_path=\"../configs/\")\n",
    "cfg = hydra.compose(config_name=\"train.yaml\")\n",
    "dm = hydra.utils.instantiate(cfg.data)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Train images (with augmentation)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "dm.setup(stage=\"fit\")\n",
    "train_ds = dm._data_train\n",
    "\n",
    "print(len(train_ds))\n",
    "\n",
    "for i in range(10):\n",
    "    item = train_ds[i]\n",
    "    img = item[\"image\"].permute(1, 2, 0)\n",
    "    mask = item[\"target_segmentation\"][1]\n",
    "    fig, ax = plt.subplots(1, 2, figsize=(10, 5))\n",
    "\n",
    "    ax[0].imshow(img)\n",
    "    ax[1].imshow(mask, cmap=\"gray\")\n",
    "    ax[0].axis(\"off\")\n",
    "    ax[1].axis(\"off\")\n",
    "\n",
    "    fig.tight_layout()\n",
    "\n",
    "    plt.show()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Validation images (no augmentation)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "dm.setup(stage=\"fit\")\n",
    "val_ds = dm._data_val\n",
    "\n",
    "print(len(val_ds))\n",
    "\n",
    "for i in range(10):\n",
    "    item = val_ds[i]\n",
    "    img = item[\"image\"].permute(1, 2, 0)\n",
    "    mask = item[\"target_segmentation\"][1]\n",
    "    fig, ax = plt.subplots(1, 2, figsize=(10, 5))\n",
    "\n",
    "    ax[0].imshow(img)\n",
    "    ax[1].imshow(mask, cmap=\"gray\")\n",
    "    ax[0].axis(\"off\")\n",
    "    ax[1].axis(\"off\")\n",
    "\n",
    "    fig.tight_layout()\n",
    "\n",
    "    plt.show()"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "monseg",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.18"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
